import { Message } from "element-ui";
import { reqGetUsersList } from "../../api/users";

const state = {
  users: [],
  total: 0,
};

const getters = {};

const actions = {
  async getUsersList({ commit }, { page, limit }) {
    try {
      const res = await reqGetUsersList(page, limit);
      commit("GET_USERS_LIST", res.data.data);
    } catch (e) {
      Message({
        type: "error",
        message: e.message,
      });
    }
  },
};

const mutations = {
  GET_USERS_LIST(state, data) {
    state.users = data.users;
    state.total = data.total;
  },
};

export default {
  namespaced: true, // 开启命名空间，避免不同vuex模块命名冲突
  state,
  getters,
  actions,
  mutations,
};
